

class PrintController < ApplicationController
  
  layout  'print'

  def packing_slip
    @roll = Roll.find(params[:id])
    
    # Generate Barcodes for all the necessary values
    @bc_style   = generate_barcode(@roll, "fabric", @roll.fabric.style_code)
    @bc_length  = generate_barcode(@roll, "length", @roll.length)
    @bc_net     = generate_barcode(@roll, "net_weight", @roll.net_weight)
    @bc_lot     = generate_barcode(@roll, "lot_number", @roll.lot_number)
  end
  
  def test_loc
    @roll = Roll.find(20)
    
    # Generate Barcodes for all the necessary values
    @bc_style   = generate_barcode(@roll, "style_code", @roll.fabric.style_code)
  end
  
  private
  
  def generate_barcode (object, attribute, value)
     uloc = object.class.name.downcase + "/" + object.id.to_s + "_" + attribute + ".gif"
     base_path = "/users/jamesmclachlan/sites/textum/public/images/"
     loc = base_path + uloc
     # add rescue logic
     code = Code39.new(value.to_s)
     code.to_img(loc, 200, 50)
     uloc
   end
  
end
